<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/6/4
 * Time: 14:53
 */

namespace app\api\controller;
use app\api\model\TaobaoorderModel;


class Taobaoorder extends BaseController
{
    public function __construct()
    {
        parent::__construct();
        $this->taobao = new TaobaoorderModel();
    }
    public function AjaxReturn($code,$msg,$data=array())
    {

        $returnData=array(
            "code"=>$code
        );
        if($msg)
        {
            $returnData["message"]=$msg;
        }
        if(!empty($data))
        {
            $returnData["data"]=$data;
        }
        exit(json_encode($returnData));
    }
 	public function type(){//查询店铺类型
     	$list=$this->taobao->type();
        if(!empty($list)){
            return $this->AjaxReturn("1",'操作成功',$list);
        }else{
            return $this->AjaxReturn("2",'操作失败');
        }
    }
    public function orderlist(){//商品列表
        $res=$this->taobao->orderlsit();
        if(!empty($res)){
        	return $this->AjaxReturn("1",'操作成功',$res);
        }else{
        	return $this->AjaxReturn("0",'暂无数据',$res);
        }
    }
  	public function search(){//商品列表的显示
        $list=$this->taobao->search();
      	if(!empty($list)){
        	return $this->AjaxReturn("1",'操作成功',$list);
        }else{
        	return $this->AjaxReturn("0",'暂无数据',$list);
        }
        
    }
    public function ordercheck(){//商品详情
        $uid=$this->uid;
        $res=$this->taobao->ordercheck($uid);//dump($res);die;
        $res['img']=explode(',',$res['img']);
      	$res['synopsis']=explode(',',$res['synopsis']);
      	$res['params'] = json_decode($res['params'],true);
        if(!empty($res)){
            return $this->Ajaxreturn('1','查询成功',$res);
        }else{
            return $this->Ajaxreturn('-1','查询失败');
        }
    }
    public function Confirmorder(){//确认订单
        $uid=$this->uid;
        $res=$this->taobao->Confirmorder($uid);
        if($res==1){
            return $this->AjaxReturn("1",'操作成功');
        }elseif($res==2){
            return $this->AjaxReturn("12",'数据不能为null');
        }elseif($res==3){
            return $this->AjaxReturn("12",'用户余额不足');
        }
    }
    public function complete(){//完成订单
        $uid=$this->uid;
        $res=$this->taobao->complete($uid);
	if($res==1){
            return $this->AjaxReturn("1",'操作成功');
        }else{
            return $this->AjaxReturn("2",'操作失败');
        }
   }
  	public function order_list(){//订单列表
    	$uid=$this->uid;
        $res=$this->taobao->order_list($uid);
      	foreach($res as $k=>$val){
          $res[$k]['createtime']=date('Y-m-d',$res[$k]['createtime']);
        }
      	if(!empty($res)){
            return $this->AjaxReturn("1",'查询成功',$res);
        }else{
            return $this->AjaxReturn("2",'没有订单');
        }
    }
    public function order_check(){//订单列表
     	$uid=$this->uid;
        $res=$this->taobao->order_check($uid);
      	if(!empty($res)){
            return $this->AjaxReturn("1",'查询成功',$res);
        }else{
            return $this->AjaxReturn("2",'没有默认地址');
        }
    }
  	public function address(){//默认地址
    	$uid=$this->uid;//dump($uid);die;
      	$res=$this->taobao->address($uid);//dump($res);die;
      	if(!empty($res)){
            return $this->AjaxReturn("1",'查询成功',$res);
        }else{
            return $this->AjaxReturn("2",'没有默认地址');
        }
    }
}